package com.ice.proxy.server;

import org.eclipse.jetty.server.Server;
import org.eclipse.jetty.servlet.BaseHolder;
import org.eclipse.jetty.servlet.FilterHolder;
import org.eclipse.jetty.servlet.ListenerHolder;
import org.eclipse.jetty.servlet.ServletContextHandler;
import org.eclipse.jetty.servlet.ServletHolder;
import org.springframework.web.context.ContextLoaderListener;
import org.springframework.web.servlet.DispatcherServlet;

/**
 * Created by ice on 7/20/16.
 */
public class ExecutorServer {
    public static void main(String[] args) throws Exception {
//        FileSystemXmlApplicationContext applicationContext = new FileSystemXmlApplicationContext("classpath:applicationContext.xml");
        new ExecutorServer().start();
    }

    public void start() throws Exception {
        Server server = new Server(8080);
        FilterHolder filterHolder = new FilterHolder();
        ServletContextHandler context = new ServletContextHandler();
        ListenerHolder listener = new ListenerHolder(BaseHolder.Source.ANNOTATION);

        context.setContextPath("/");
        server.setHandler(context);
        listener.setListener(new ContextLoaderListener());

        ServletHolder servletHolder = context.addServlet(DispatcherServlet.class, "/*");
        servletHolder.setInitOrder(0);
        servletHolder.setInitParameter("contextConfigLocation", "classpath:spring-servlet.xml");

        try {
            server.start();
            server.join();
        } finally {
            server.destroy();
        }
    }
}
